package com.example.administrator.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.nle.mylibrary.enums.led.PlayType;
import com.nle.mylibrary.enums.led.ShowSpeed;
import com.nle.mylibrary.forUse.led.LedScreen;
import com.nle.mylibrary.forUse.rfid.RFID;
import com.nle.mylibrary.forUse.rfid.RFIDReadListener;
import com.nle.mylibrary.transfer.DataBusFactory;

public class MainActivity extends AppCompatActivity {
    private Button find;
    private RFID rfid;
    private TextView tv_show;
    private LedScreen led;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        find=findViewById(R.id.find);
        tv_show=findViewById(R.id.tv_show);
        rfid = new RFID(DataBusFactory.newSocketDataBus("192.168.0.200", 951));
        led=new LedScreen(DataBusFactory.newSocketDataBus("192.168.1.203",4196));

        find.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    rfid.readData(new RFIDReadListener() {
                        @Override
                        public void onResult(final String str) {
                            try {
                                led.switchLed(true);
                                led.sendTxt(str,PlayType.LEFT,ShowSpeed.SPEED3,1,100);
                                led.switchLed(false);
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        tv_show.setText(str);
                                    }
                                });
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
